package com.Service.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package com.Service.advice
 * @date 2024/4/24 下午7:17
 */
@Component
@Aspect
public class Around {

    /*
     * 环绕通知需要在增强中定义目标方法的执行
     *
     * jointpoint 目标方法
     * return 目标方法的返回值
     * */
    public Object transaction(ProceedingJoinPoint proceedingJoinPoint) {
        //保证目标方法执行
        Object[] args = proceedingJoinPoint.getArgs();
        Object proceed = null;
        try {
            //增强代码->before
            System.out.println("start");
            proceed = proceedingJoinPoint.proceed(args);
            System.out.println("ending");
        } catch (Throwable e) {
            System.out.println("rollback");
            throw new RuntimeException(e);
        }
        return proceed;

    }
}
